home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ggraph / hist.c < prev    next >
C/C++ Source or Header  |  1989-07-12  |  4KB  |  130 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <strings.h>
  4. #include <math.h>
  5. #include "ggraph.h"
  6. #include "ggraphdefs.h"
  7. /****************************************************************
  8.  *                                *
  9.  *    hist - write the points of a histogramn            *
  10.  *                                *
  11.  ****************************************************************/
  12. hist ()
  13. {
  14.     register int     i;
  15.     register float llabxl, llabyl;
  16.     register float prevx, prevy;
  17.     int clipped = 0;
  18.  
  19.     prevx = prevy = 0.0;    /* init values first */
  20.     for (curline = 0; ((curline != cg.maxlines) && (cl != NULL)); ++curline) {
  21.     if (cl->lonoff) {
  22.     /* connect the dots */
  23.         if(cl->ctype){
  24.         fprintf (outfile, "%d\n", cl->ctype);
  25.             prevx = ((0.0 - cg.xoffset) * cg.scalex) + cg.xorigin;
  26.             prevy = ((0.0 - cg.yoffset) * cg.scaley) + cg.yorigin;
  27.         fprintf (outfile, "%4.1f %4.1f\n", prevx, prevy);
  28.         graphy = ((cl->ypoints[0] - cg.yoffset) * cg.scaley)
  29.           + cg.yorigin;
  30.         if((graphy < 0.0)||(graphy > 512.0) || 
  31.         (prevx < 0.0)||(prevx > 512.0))
  32.           fprintf(stderr,"Point out of range\n");
  33.         else
  34.         if((graphy < cg.yorigin)||(graphy > cg.yplotmax) || 
  35.               (prevx < cg.xorigin)||(prevx > cg.xplotmax)) {
  36.                 fprintf(stderr,"%s:Point off graph clipped\n", 
  37.                    graphname);
  38.                 fprintf(outfile, 
  39.                        (version == SUN_GREMLIN) ?
  40.                        "*\n" : "-1.00 -1.00\n");
  41.                 fprintf (outfile, "%d %d\n%d\n", cl->ltype, 0, 0);
  42.                 fprintf (outfile, "%d\n", cl->ctype);
  43.             } 
  44.         else
  45.             fprintf (outfile, "%4.1f %4.1f\n", prevx, graphy);
  46.         prevx = ((cl->xpoints[0] - cg.xoffset) * cg.scalex)
  47.           + cg.xorigin;
  48.         for (i = 0; i < cl->maxpoint; i++) {
  49.             graphx = ((cl->xpoints[i] - cg.xoffset) * cg.scalex)
  50.               + cg.xorigin;
  51.         graphy = ((cl->ypoints[i] - cg.yoffset) * cg.scaley)
  52.           + cg.yorigin;
  53.         if((graphx < 0.0)||(graphx > 512.0) || 
  54.         (prevy < 0.0)||(prevy > 512.0))
  55.             fprintf(stderr,"Point out of range\n");
  56.         else
  57.             if((graphy < cg.yorigin)||(graphy > cg.yplotmax) || 
  58.               (prevx < cg.xorigin)||(prevx > cg.xplotmax)) {
  59.                 fprintf(stderr,"%s:Point off graph clipped\n", 
  60.                    graphname);
  61.                 if (!clipped) {
  62.                     fprintf(outfile, 
  63.                        (version == SUN_GREMLIN) ?
  64.                        "*\n" : "-1.00 -1.00\n");
  65.                     fprintf (outfile, "%d %d\n%d\n",
  66.                         cl->ltype, 0, 0);
  67.                     clipped = 1;
  68.                 } 
  69.             } 
  70.             else {
  71.                 if (clipped) {
  72.                     fprintf (outfile, "%d\n", cl->ctype);
  73.                     clipped = 0;
  74.                 } 
  75.                 fprintf (outfile, "%4.1f %4.1f\n", prevx, graphy);
  76.             } 
  77.         if((graphy < 0.0)||(graphy > 512.0) || 
  78.         (graphx < 0.0)||(graphx > 512.0))
  79.             fprintf(stderr,"Point out of range\n");
  80.         else
  81.             if((graphy < cg.yorigin)||(graphy > cg.yplotmax) || 
  82.               (graphx < cg.xorigin)||(graphx > cg.xplotmax)) {
  83.                 fprintf(stderr,"%s:Point off graph clipped\n", 
  84.                    graphname);
  85.                 if (!clipped) {
  86.                     fprintf(outfile, 
  87.                        (version == SUN_GREMLIN) ?
  88.                        "*\n" : "-1.00 -1.00\n");
  89.                     fprintf (outfile, "%d %d\n%d\n", 
  90.                         cl->ltype, 0, 0);
  91.                     clipped = 1;
  92.                 } 
  93.             } 
  94.             else {
  95.                 if (clipped) {
  96.                     fprintf (outfile, "%d\n", cl->ctype);
  97.                     clipped = 0;
  98.                 } 
  99.                 fprintf (outfile, "%4.1f %4.1f\n", graphx, graphy);
  100.             } 
  101.         prevx = graphx;
  102.         prevy = graphy;
  103.         }
  104.             prevy = ((0.0 - cg.yoffset) * cg.scaley) + cg.yorigin;
  105.         fprintf (outfile, "%4.1f %4.1f\n", prevx, prevy);
  106.         fprintf(outfile, (version == SUN_GREMLIN) ? "*\n" : "-1.00 -1.00\n");
  107.         fprintf (outfile, "%d %d\n%d\n", cl->ltype, 0, 0);
  108.         }
  109.         if (cl->llabsw) {
  110.         if(cl->llabel.t_text[0] == NULL)
  111.             strcpy (cl->llabel, cl->lname);
  112.         if(!cl->llabel.t_xpos)
  113.             llabxl = (cl->xpoints[cl->maxpoint-1] * cg.scalex)
  114.              + cg.xorigin - 10.0;
  115.         else
  116.             llabxl = (cl->llabel.t_xpos * cg.scalex) + cg.xorigin - 10.0;
  117.         if(!cl->llabel.t_ypos)
  118.             llabyl = (cl->ypoints[cl->maxpoint-1] * cg.scaley)
  119.              + cg.yorigin + 5.0;
  120.         else
  121.             llabyl = (cl->llabel.t_ypos * cg.scaley)
  122.             + cg.yorigin + 5.0;
  123.         drawctext (llabxl, llabyl, cl->llabel.t_font, cl->llabel.t_size,
  124.           cl->llabel.t_text, TOPCENTER_TEXT);
  125.         }
  126.     }
  127.     }
  128. }
  129.  
  130.